create table Ticket
(
	 [TicketId] int identity(1, 1) primary key
	,[ConcernId] int
	,[ScheduleId] int
	,[TicketName] nvarchar(128)
	,[SortDescription] nvarchar(512)
	,[DetailDescription] nvarchar(max)
	,[TypeId] int
	,[TotalTicket] int
	,[SaleTicket] int
	,[RegisterYear] int
	,[CreatedBy] int
	,[CreatedDate] datetime
	,[UpdatedBy] int
	,[UpdatedDate] datetime
	,[Status] int
)
go

CREATE PROCEDURE TicketGet
	@TicketId int
AS
SELECT *
FROM [Ticket]
WHERE [Ticket].[TicketId] = @TicketId
GO

CREATE PROCEDURE TicketList
AS
SELECT *
FROM [Ticket]
ORDER BY TicketId DESC
GO

CREATE PROCEDURE TicketInsert
	@ConcernId int
	,@ScheduleId int
	,@TicketName nvarchar(128)
	,@SortDescription nvarchar(512)
	,@DetailDescription nvarchar(max)
	,@TypeId int
	,@TotalTicket int
	,@SaleTicket int
	,@RegisterYear int
	,@CreatedBy int
	,@CreatedDate datetime
	,@UpdatedBy int
	,@UpdatedDate datetime
	,@Status int
AS

INSERT INTO Ticket (
	 [ConcernId]
	,[ScheduleId]
	,[TicketName]
	,[SortDescription]
	,[DetailDescription]
	,[TypeId]
	,[TotalTicket]
	,[SaleTicket]
	,[RegisterYear]
	,[CreatedBy]
	,[CreatedDate]
	,[UpdatedBy]
	,[UpdatedDate]
	,[Status]
	
) VALUES (
	 @ConcernId
	,@ScheduleId
	,@TicketName
	,@SortDescription
	,@DetailDescription
	,@TypeId
	,@TotalTicket
	,@SaleTicket
	,@RegisterYear
	,@CreatedBy
	,@CreatedDate
	,@UpdatedBy
	,@UpdatedDate
	,@Status
	
)

select SCOPE_IDENTITY()
GO

CREATE PROCEDURE TicketUpdate
	@TicketId int, 
	@ConcernId int, 
	@ScheduleId int, 
	@TicketName nvarchar(128), 
	@SortDescription nvarchar(512), 
	@DetailDescription nvarchar(max), 
	@TypeId int, 
	@TotalTicket int, 
	@SaleTicket int, 
	@RegisterYear int, 
	@CreatedBy int, 
	@CreatedDate datetime, 
	@UpdatedBy int, 
	@UpdatedDate datetime, 
	@Status int 

AS

UPDATE Ticket SET
	   [ConcernId] = @ConcernId
	   ,[ScheduleId] = @ScheduleId
	   ,[TicketName] = @TicketName
	   ,[SortDescription] = @SortDescription
	   ,[DetailDescription] = @DetailDescription
	   ,[TypeId] = @TypeId
	   ,[TotalTicket] = @TotalTicket
	   ,[SaleTicket] = @SaleTicket
	   ,[RegisterYear] = @RegisterYear
	   ,[CreatedBy] = @CreatedBy
	   ,[CreatedDate] = @CreatedDate
	   ,[UpdatedBy] = @UpdatedBy
	   ,[UpdatedDate] = @UpdatedDate
	   ,[Status] = @Status
WHERE [Ticket].[TicketId] = @TicketId
GO

CREATE PROCEDURE TicketDelete
	@TicketId int
AS
DELETE FROM Ticket
WHERE [Ticket].[TicketId] = @TicketId
GO